﻿<?php
require_once("_config-rating.php");
if (isset($_GET["page"])) 
{ 
	$page  = $_GET["page"]; 
} else { 
	$page=1; 
};

if (!$con)
{
	die('Could not connect: ' . mysql_error());
}


$sql = "SELECT COUNT(*) FROM games ";
$rs_result = mysql_query($sql,$con); 
if ($row = mysql_fetch_array($rs_result)){
	
$total_records = $row[0]; 
$total_pages = ceil($total_records / $pageInclude); 
$outputPagination='<div>';
$outputPagination=$outputPagination.'<div align="center" ><ol class="wp-paginate"><li><span class="title"></span></li>';

$startPage=1;
$pageCount=2;
if ($pageCount>=$total_pages){
	$startPage=1;
	$loopCount=$total_pages;
}else if($page+$pageCount<=$total_pages){
	if ($page>1)$startPage=$page-1;
	else $startPage=1;
	$loopCount=$startPage+$pageCount;
}else if($page+$pageCount>$total_pages){
	$startPage=$total_pages-$pageCount;
	$loopCount=$startPage+$pageCount;
}
/*if($page+$pageCount<=$total_pages && $page-1>0){
	$startPage=$page-1;
}else if($page+$pageCount>$total_pages){
	$startPage=$total_pages-$pageCount;
}*/

if(($page-1)>0){
	$outputPagination=$outputPagination.'<li><a class="next" href="'.$direction.'?page='.($page-1).'&category='.$category.'">«</a></li>';
}
for ($i=$startPage; $i<=$loopCount; $i++) { 
	if($page==$i){
		$outputPagination=$outputPagination.'<li><span class="page current">'.$i.'</span></li>';
	}else{
		$outputPagination=$outputPagination.'<li><a class="page" title='.$i.' href="'.$direction.'?page='.$i.'&category='.$category.'">'.$i.'</a></li>';
	}
    //echo "<a href='pagination.php?page=".$i."'>".$i."</a> "; 
};
if(($page+1)<=$total_pages){
	$outputPagination=$outputPagination.'<li><a class="next" href="'.$direction.'?page='.($page+1).'&category='.$category.'">»</a></li>';
}

$outputPagination=$outputPagination.'</ol></div></div>';
}

echo $outputPagination;

mysql_close();
?>